/*
 * MutableFont.cpp
 *
 *  Created on: 2018年8月13日
 *      Author: zhengboyuan
 */

#include "MutableFont.h"
#include "FaceText.h"


MutableFont::MutableFont():
	m_font(),
	m_type(),
	m_size()
{
}

MutableFont::~MutableFont()
{
	deleteObject();
}

HFONT MutableFont::create(int type, int size)
{
	deleteObject();

	std::string name;
	if (type == FaceText::kSun)
	{
		name = "simsun";
	}
	else if (type == FaceText::kArial)
	{
		name = "Arial";
	}
	
	m_font = CreateFontA(size, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
		CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_MODERN, name.c_str());

	m_type = type;
	m_size = size;

	return m_font;
}

HFONT MutableFont::update(int type, int size)
{
	if (m_font == NULL)
	{
		return create(type, size);
	}

	if (type != m_type || m_size != size)
	{
		return create(type, size);
	}
	return m_font;
}

HFONT MutableFont::get()
{
	return m_font;
}

void MutableFont::deleteObject()
{
	if (m_font)
	{
		DeleteObject(m_font);
		m_font = NULL;
	}
}
